#include "ccd290_fits.h"
#include "dictionary.h"
#include "iniparser.h"

fits_header* create_fits_header(int size){
    
    fits_header* fh = (fits_header*)malloc(sizeof(fits_header));
    fh->size        = size;
    fh->key_value   = (fits_key_value*)malloc(sizeof(fits_key_value)*size);
    
    int i;
    for(i=0; i<size; i++){
        (fh->key_value)[i].status = 0;
        sprintf((fh->key_value)[i].key, "NONE");
        sprintf((fh->key_value)[i].value, "NULL");
        sprintf((fh->key_value)[i].comment, "EMPTY");
    }

    return fh;
}

void destroy_fits_header( fits_header* fh ){
    free(fh->key_value);
    free(fh);
}

int init_fits_header( fits_header *fh, char *ptr_ini ){
    
}

int fits_header_write_keys( fitsfile *fptr, fits_header *fh ){
    int i, status;
    for( i=0; i<fh->size; i++ ){
        if( fh->key_value[i].status == 1 ){
            
            printf("FITS HEAD --> %s | %s | %s\n", 
                    fh->key_value[i].key, 
                    fh->key_value[i].value,
                    fh->key_value[i].comment );

            fits_update_key(fptr, 
                            TLONG, 
                            fh->key_value[i].key, 
                            &(fh->key_value[i].value), 
                            &(fh->key_value[i].comment),
                            &status);
        }
    }
}

